package com.forehope.portal.aslpUtil;

import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.AppAPI;
import net.sf.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class MailUtil {
    //获取邮件模板
    public static String getMaiTemplate(String id) {
// 调用App
        String sourceAppId = "com.actionsoft.apps.addons.mail";
// aslp服务地址
        String aslp = "aslp://com.actionsoft.apps.addons.mail/getTemplate";
// 参数定义列表
        Map params = new HashMap<String, Object>();
//邮件模板id,必填
        params.put("id", id);
        AppAPI appAPI = SDK.getAppAPI();
//获取一个邮件模板
        ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params);
        JSONObject data = ro.getData(JSONObject.class);
        return data.getString("email_content");
    }
    public static void sendMailToUser(String subject, String content, String toUser, String cc) {

// 调用App
        String sourceAppId = "com.actionsoft.apps.addons.mail";
// aslp服务地址
        String aslp = "aslp://com.actionsoft.apps.addons.mail/sendMail";
// 参数定义列表
        Map params = new HashMap<String, Object>();
//邮件主题,必填
        params.put("subject", subject);
//附件，Map<String, byte[]> key是附件名/value是附件字节,非必填
//        params.put("files", files);
//收件人地址，多个用;隔开,必填
        params.put("to", toUser);
//收件人地址，多个用;隔开,必填
        params.put("cc", cc);
//邮件征文,必填
        params.put("content", content);
        AppAPI appAPI = SDK.getAppAPI();
//发送邮件
        System.out.println("---------------toUser:"+toUser);
        System.out.println("---------------content:"+content);
        appAPI.asynCallASLP(appAPI.getAppContext(sourceAppId), aslp, params);
    }
}
